{include file='common/head' /}
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <input type="hidden" name="id" value="{$data.id|default=''}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>分类名称
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" required="" autocomplete="off" class="layui-input" value="{$data.name|default=''}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>不允许为空
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            分类排序
                        </label>
                        <div class="layui-input-inline">
                            <input type="number" name="sort" required="" autocomplete="off" class="layui-input" value="{$data.sort|default='0'}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>值大的拍在前面，最高99999，不填默认0
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            是否启用
                        </label>
                        <div class="layui-input-inline">
                            {if condition="empty($data['status'])"}
                            <input type="radio" name="status" value="1" title="是">
                            <input type="radio" name="status" value="0" title="否" checked>
                            {else /}
                            <input type="radio" name="status" value="1" title="是" {if condition="$data['status'] eq 1"}checked{/if}>
                            <input type="radio" name="status" value="0" title="否" {if condition="$data['status'] eq 0"}checked{/if}>
                            {/if}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">确定保存</button></div>
                </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer','jquery'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //监听提交
                form.on('submit(add)', function(data) {
                    var num = $('[lay-submit]').index($(this));
                    var formData = new FormData($('form')[num]);
                    //发异步，把数据提交给php
                    $.ajax({
                        url:"{:url('Lives/type_edit')}",
                        type: "post",
                        data:formData,
                        dataType:"json",
                        cache: false,                      // 不缓存
                        processData: false,                // jQuery不要去处理发送的数据
                        contentType: false,                // jQuery不要去设置Content-Type请求头
                        success:function (res) {
                            if(res.code == 200){
                                layer.alert(res.msg, {icon: 1},function () {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                            }else{
                                layer.alert(res.msg, {icon: 5});
                            }
                        },
                        error:function(e){
                            layer.alert("网络错误", {icon: 5});
                        },
                    });
                    return false;
                });
            });
        </script>
{include file='common/footer' /}